/**
 * 窗口工具集
 * @auther: kikolove
 */

const minimizeWin = (mainWindow) => {
    mainWindow.minimize();
};

const maximizeWin = (mainWindow) => {
    mainWindow.maximize();
}

const unmaximizeWin = (mainWindow) => {
    mainWindow.unmaximize();
}

const closeWin = (mainWindow) => {
    mainWindow.close();
}
// 最大化和还原窗口, 返回当前窗口是否最大化
const maxAndRestoreWin = (mainWindow) => {
    if (isMaximized(mainWindow)) {
        unmaximizeWin(mainWindow);
        return false;
    } else {
        maximizeWin(mainWindow);
        return true;
    }
}

const isMaximized = (mainWindow) => {
    return mainWindow.isMaximized();
}

//监听窗口大小变化，判断是否最大化
const listenWinResize = (mainWindow) => {
    mainWindow.on('resize', () => {
        if (isMaximized(mainWindow)) {
            mainWindow.webContents.send('isMaximized', true);
        } else {
            mainWindow.webContents.send('isMaximized', false);
        }
    })
}

export { minimizeWin, maximizeWin, unmaximizeWin, closeWin, maxAndRestoreWin, isMaximized, listenWinResize }
